<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JS020-事件流</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }

    body {
        background-color: #222;
        color: snow;
    }

    .father {
        position: absolute;
        inset: 2rem;
        background-color: skyblue;
    }

    .son {
        position: absolute;
        inset: 2rem;
        background-color: steelblue;
    }
</style>

<body>
    <div class="father">
        <div class="son"></div>
    </div>
    <script>
        document.addEventListener('click', function (e) {
            console.log(`${this}我是祖宗`);
        }, true); //捕获阶段触发，所以是第一个触发
        document.querySelector('.father').addEventListener('click', function (e) {
            console.log(`${this}我是爸爸`);
        }); //冒泡阶段触发
        document.querySelector('.son').addEventListener('click', function (e) {
            console.log(`${this}我是儿子`);
            e.stopPropagation(); //阻止冒泡
        }); //冒泡阶段触发
        //1.捕获阶段：祖宗(第1触发)->爸爸->儿子
        //2.冒泡阶段：儿子(第2触发，并阻止冒泡)->爸爸(本来是第3触发)->祖宗

    </script>
</body>

</html>